#include "currenttimeitem.h"
#include <QTime>
#include <QPainter>
#include <QTimer>

CurrentTimeItem::CurrentTimeItem()
{
    timer = new QTimer(this);
    connect(timer,SIGNAL(timeout()),this,SLOT(updateTime()));
    timer->setInterval(1000);
    timer->start();

    strTime = QTime::currentTime().toString("hh:mm");
}

void CurrentTimeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->drawText(QRectF(0.0f,0.0f,60.0f,40.0f),
                      Qt::AlignCenter,
                      strTime);
}

QRectF CurrentTimeItem::boundingRect() const
{
    return QRectF(0.0f,0.0f,120.0f,40.0f);
}

void CurrentTimeItem::updateTime()
{
    strTime = QTime::currentTime().toString("hh:mm");
}
